<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>赛事列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/iconfont.css">
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/xadmin.css">
    <link rel="stylesheet" href="../lib/layui/css/modules/laydate/default/laydate.css">
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/jquery.min.js"></script>
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="../js/base.js"></script>
    <script src="../lib/layui/lay/modules/laydate.js"></script>
    <style>
        tr td,
        tr th {
            text-align: center !important;
            border: none !important;
        }

        .layui-laydate-content tr td {
            border-bottom: none !important;
            border-top: none !important;
        }

        tr td {
            border-bottom: 1px solid #eee !important;
            border-top: 1px solid #eee !important;
        }

        .layui-form-select {
            width: 100px;
            float: left;
            display: inline-block;
            vertical-align: middle;
        }

        .layui-show-xs-block input {
            border: 1px solid #e6e6e6;
            border-radius: 4px;
            height: 30px;
            line-height: 30px;
            padding-left: 6px;
        }

        .layui-show-xs-block label {
            float: left;
            display: block;
            width: 66px;
            line-height: 32px;
            text-align: right;
            margin-right: 10px;
        }

        .search {
            margin-left: 20px;
        }
    </style>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <!-- <div class="layui-col-md12">
            <div class="layui-card" style="display: flex;justify-content: space-between;">
                <div class="layui-card-body ">
                    <blockquote class="layui-elem-quote" style="border:0;font-size: 18px;color: #000;">赛事列表
                    </blockquote>
                </div>
            </div>
        </div> -->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-fluid">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-card-body " style="display: flex;justify-content:space-between">
                                <form class="layui-form" action="">
                                    <div class="layui-inline layui-show-xs-block">
                                        <label>关键字搜索</label>
                                        <input type="text" id="name">
                                    </div>
                                    <div class="layui-inline layui-show-xs-block">
                                        <label>开始时间</label>
                                        <input type="text" id="test2">
                                    </div>
                                    <div class="layui-inline layui-show-xs-block">
                                        <label>赛事数据</label>
                                        <select id="competitionData" name="competitionData">
                                            <option value="">全部</option>
                                            <option value="已完善">已完善</option>
                                            <option value="数据待完善">数据待完善</option>
                                        </select>
                                    </div>
                                    <div class="layui-inline layui-show-xs-block">
                                        <button class="layui-btn search" data-type="reload"
                                                lay-filter="add">查询
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-body layui-table-body layui-table-main">
            <!-- 表格部分开始 -->
            <table id="video_table" lay-filter="test" lay-data="{id: 'testReload'}"></table>
            <script type="text/html" id="barDemo">
                <a lay-event="watch" class="btn_a layui-btn layui-btn-xs">报名</a>
                <!-- <a lay-event="edit" class="btn_a layui-btn layui-btn-xs">编辑</a> -->
                <!-- <a lay-event="del" class="btn_a layui-btn layui-btn-danger layui-btn-xs">删除</a> -->
            </script>
            <!-- 表格结束 -->
        </div>
    </div>
</div>
</div>
</body>
</html>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#test'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#test2'
            , type: 'month'
        });
    });
    layui.use('table', function () {
        var table = layui.table;
        var form = layui.form;
        var index = layer.load(1); //添加laoding,0-2两种方式
        //第一个实例
        var ins1 = table.render({
            elem: '#video_table', //指定原始表格元素选择器（推荐id选择器）
            // height: 600,
            width: "100%",
            // 附加参数，post token
            // where: { 'token': token },
            loading: true,
            method: 'get',
            url: findNewcompetitionMessageListByAdminId, //数据接口
            page: true, //开启分页
            // toolbar: 'default', //开启工具栏，此处显示默认图标
            cols: [
                [ //表头
                    // { type: 'checkbox', fixed: 'left' },
                    {
                        field: 'id',
                        title: 'ID',
                        width: 150
                    },
                    {
                        field: 'name',
                        title: '赛事名称',
                        width: 150
                    },
                    {
                        field: 'organizers',
                        title: '主办方',
                        width: 150
                    },
                    {
                        field: 'city',
                        title: '举办地',
                        width: 150
                    },
                    {
                        field: 'competitionStartTime',
                        title: '开始时间',
                        width: 150
                    },
                    {
                        field: 'addTime',
                        title: '申请提交时间',
                        width: 150
                    },
                    {
                        fixed: 'right',
                        title: "操作",
                        width: 150,
                        align: 'center',
                        toolbar: '#barDemo'
                    }
                ]
            ],
            id: 'testReload',
            done: function (res) {
                console.log(res)
                if (res.msg == "2") {
                    parent.window.location.href = getRequestPrefix() + "/footBallAdmin/login.html"
                }
                layer.close(index)
            }
        });


        //头部输入框筛选功能
        var $ = layui.$,
            active = {
                reload: function () {
                    var name = $('#name')
                    var competitionData = $('#competitionData');
                    var city = $('#city');
                    var date = $('#date');
                    // 执行重载（重新加载数据表格）
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                        where: {
                            "name": name.val(),
                            "competitionData": competitionData.val(),
                            "city": city.val(),
                            "date": date.val(),
                        }
                    }, 'data');
                }
            };


        //给查询添加点击事件
        $('.search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
            //一定要阻止表单的默认行为（刷新）
            return false
        });

        //监听头工具栏事件
        //监听点击的按钮，获取行信息
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            //获得当前行数据
            var $ = layui.$
            var data = obj.data,
                layEvent = obj.event; //获得 lay-event 对应的值
            //点击报名
            if (layEvent === "watch") {
                // console.log(data)
                var competitionId = data.id
                var userId = data.userId
                layer.confirm("确定报名吗", function (index) {
                    $.ajax({
                        url: recruitreferee,
                        type: 'get',
                        data: {
                            userId: userId,
                            competitionId: competitionId,
                        },
                        dataType: 'json',
                        success: function (data) {
                            console.log(data)
                            if (data.msg == 0) {
                                layer.alert('报名成功', {
                                    title: '提示'
                                })
                                table.reload('testReload');
                            } else {
                                layer.alert(data.msg, {
                                    title: '提示'
                                })
                            }
                        },
                        error: function (data) {
                            console.log(data)
                            layer.alert(data.msg, {
                                title: '提示'
                            })
                        }
                    });
                    layer.close(index)
                })
            }
            ;
        });
    });
</script>